package com.hfstu.framework.db;



import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;

public class DBTest implements Runnable /* extends Thread */{
	public long date1 = 0;
	public static int count = 0;
	public DBConnectionManager connMgr = DBConnectionManager.getInstance();

	public static void main(String[] args) throws Exception {
		DBTest test = new DBTest();
		test.startup();
	}

	public void startup() {
		for (int i = 0; i < 5; i++) {
			Thread thread = new Thread(this);
			thread.start();
		}
	}

	public void run() {
		if (count == 0 && date1 == 0) {
			date1 = System.currentTimeMillis();
			System.out.println(date1);
		}
		for (int i = 0; i < 10; i++) {
			try {
				Connection conn = connMgr.getConnection("ifs");
				if (conn != null) {
					Statement statement = conn.createStatement();
					ResultSet rs = statement
							.executeQuery("select * from sword_pms_staff u where u.username = 'root'");
					while (rs.next()) {
						String username = rs.getString(2);
						System.out.println( Thread.currentThread().getName() + " :" + username);
					}
					connMgr.close("ifs", conn, statement, rs);
				}
			} catch (SQLException e) {
				e.printStackTrace();
			}
		}
		count++;
		/*
		 * if (currThreadName.equals("Thread-4")) { long date2 =
		 * System.currentTimeMillis(); System.out.println(date2);
		 * System.out.println("�������!��ʱΪ��" + (date2 - date1) + "ms"); }
		 */
		if (count == 5) {
			long date2 = System.currentTimeMillis();
			System.out.println(date2);
			System.out.println("all time = " + (date2 - date1) + "ms");
		}
	}
}